package com.small.xx.ai.mcp.server.base.component;

import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Component;

import java.sql.SQLException;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;

@Component
public class ToolComponent implements BaseToolComponent {

    @Tool(description = "可以获取到某个城市的天气信息")
    public Map<String, String> getWeather(
        @ToolParam(required = true, description = "入参城市，请传入城市拼音") String city) throws SQLException {
        System.out.println("获取到了城市信息:" + city);
        return Map.of("datas", city + "的天气为大雪");
    }

    @Tool(description = "可以获取指定时区的当前时间信息")
    public String getCityTimeMethod(@ToolParam(description = "时区，比如Asia/Shanghai") String timeZoneId) {
        System.out.println("获取时区的 = " + timeZoneId);
        if (timeZoneId == null || timeZoneId.isEmpty()) {
            timeZoneId = "Asia/Shanghai";
        }
        // Get the time zone using ZoneId
        ZoneId zid = ZoneId.of(timeZoneId);
        // Get the current time in this time zone
        ZonedDateTime zonedDateTime = ZonedDateTime.now(zid);
        // Defining a formatter
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");
        // Format ZonedDateTime as a string
        return zonedDateTime.format(formatter);
    }
}